<form role="form" action="" class="frm-operate" method="post" novalidate>
    <div class="card card-primary card-tabs">
        <div class="card-header">
            <ul class="nav nav-tabs">
                <li class="nav-item">
                    <a class="nav-link active" data-toggle="pill" href="#tabs-for-base" role="tab">{:lang("Base")}</a>
                </li>
                {volist name="fieldGroup" id="vo"}
                {if ($vo!='常规')}
                <li class="nav-item">
                    <a class="nav-link" data-toggle="pill" href="#tabs-for-{$i}" role="tab">{$vo}</a>
                </li>
                {/if}
                {/volist}
            </ul>
        </div>
        <div class="card-body">
            <div class="tab-content">
                <div class="tab-pane fade active show" id="tabs-for-base" role="tabpanel">
                    <div class="form-group row">
                        <label for="frm-category_id" class="col-sm-2 col-12 col-form-label">{:lang("Column")}：</label>
                        <div class="col-sm-8 col-12">
                            <select id="frm-category_id" class="form-control">
                                {volist name="category_list" id="vo"}
                                <option value="{$vo.id}"
                                        {if $vo['model_id']!=$categoryInfo['model_id']}disabled style="background-color:#f5f5f5;"{/if}
                                {if $vo['id'] == $categoryInfo['id']}selected{/if}
                                >{$vo.title|raw}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>

                    <input type="hidden" name="row[category_id]" value="{$categoryInfo['id']}">

                    {if !empty($modelFieldArr['常规'])}{$modelFieldArr['常规']|raw}{/if}

                </div>
                {volist name="fieldGroup" id="vo"}
                {if ($vo!='常规')}
                <div class="tab-pane fade" id="tabs-for-{$i}" role="tabpanel">
                    {if !empty($modelFieldArr[$vo])}{$modelFieldArr[$vo]|raw}{/if}
                </div>
                {/if}
                {/volist}
            </div>
        </div>
        <div class="card-footer">
            <div class="row justify-content-around">
                <div class="col-sm-10">
                    <button type="submit" class="btn btn-primary btn-submit">{:lang('Submit')}</button>
                    <button type="reset" class="btn btn-default">{:lang('Reset')}</button>
                </div>
            </div>
        </div>
        <!-- /.card -->
    </div>
</form>

{block:script}
<script>
    require(['jquery','adminlte', 'Form','layer'], function ($, undefined, Form, undefined) {
        var initData = '';
        $(function () {
            Form.api.init({
                success:function (data) {
                    layer.msg(lang('Successful operation'), {time: 2000, icon:1}, function () {
                        if (Tpl.c_popup!=3) {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.document.getElementById('iframe1').contentWindow.$('#table').bootstrapTable('refresh');
                        } else {
                            window.location.reload();
                        }
                    })
                    return false;
                }
            })

            initData = JSON.stringify({ dataform: $(".frm-operate").serializeArray() });

            $('#frm-category_id').change(function (e) {
                var jsonText = JSON.stringify({ dataform: $(".frm-operate").serializeArray() });
                if(initData!=jsonText){
                    var that = this;
                    layer.confirm('{:lang("The form will reload the page, confirm?")}', {icon: 3, title:'{:lang("Prompt information")}'}, function (index) {
                        window.location.href = '{:url("/cms.archives/add",["popup"=>1])}&category_id='+$(that).val();
                        layer.close(index);
                    }, function (index) {
                        $('#frm-category_id').val($('input[name="row[category_id]"]').val());
                        layer.close(index);
                    });
                } else {
                    window.location.href = '{:url("/cms.archives/add",["popup"=>1])}&category_id='+$(this).val();
                }
            });
        })
    })
</script>
{/block:script}

